package com.cloud.drore.eboss.supplier.controller;


import com.cloud.drore.eboos.common.base.PagePo;
import com.cloud.drore.eboos.common.base.ResultMessage;
import com.cloud.drore.eboos.common.entity.base.UserInfo;
import com.cloud.drore.eboos.common.entity.supplier.vo.FinaceSupplierIncomeDetailsVo;
import com.cloud.drore.eboos.common.util.LocalData;
import com.cloud.drore.eboos.exception.BusinessException;
import com.cloud.drore.eboss.operation.entity.FinaceSettlementHistoryOperation;
import com.cloud.drore.eboss.operation.entity.po.DictionaryOrderPo;
import com.cloud.drore.eboss.operation.entity.po.FinaceSettlementHistoryPo;
import com.cloud.drore.eboss.operation.entity.po.FinaceSourseDataOperationPo;
import com.cloud.drore.eboss.operation.entity.vo.FinaceSourseDataOperationAndSupplierVo;
import com.cloud.drore.eboss.operation.service.impl.FinaceFormOperationServiceImpl;
import com.cloud.drore.eboss.operation.service.impl.FinaceSettlementHistoryServiceImpl;
import com.cloud.drore.eboss.supplier.entity.po.FinaceSupplierIncomeDetailsPo;
import com.cloud.drore.eboss.supplier.entity.vo.ProductQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 浙江卓锐科技股份有限公司 版权所有 © Copyright 2018<br>
 *
 * @Description: finace<br>
 * @Project: eboos <br>
 * @CreateDate: Created in 2018/01/24 11:23 <br>
 * @Author: <a href="410508961@qq.com">夏凯</a>
 */
@Slf4j
@RestController
@RequestMapping("/finaceSupplier")
@Api(value = "/供应商财务接口", description = "供应商财务管理结算记录、收入报表查询接口-夏凯")
public class FinaceSupplierController {
    @Resource
    FinaceSettlementHistoryServiceImpl finaceSettlementHistoryServiceImpl;
    @Resource
    FinaceFormOperationServiceImpl finaceOperationServiceImpl;

    @ApiOperation(value = "通过供应商id查询产品编号")
    @GetMapping(value = "/getProductIdList/{id}")
    public ResultMessage<List<ProductQueryVo>> get(@PathVariable("id") Long id) {
        UserInfo currentUser = LocalData.getCurrentUser();
        log.info("通过供应商id查询产品编号的id为" + currentUser.getTypeId());
        return finaceOperationServiceImpl.findProductNum(currentUser.getTypeId());
    }

    @ApiOperation(value = "通过分销商id和产品编号以及供应商的id（必传后台提供）、起止时间（必传）搜索供应商账单（供应商）")
    @PostMapping(value = "/queryFinaceFormListByChoice")
    public ResultMessage<List<FinaceSourseDataOperationAndSupplierVo>> queryFinaceFormListByChoice(@RequestBody @Valid PagePo<FinaceSourseDataOperationPo> page) throws BusinessException {
        return finaceSettlementHistoryServiceImpl.queryFinaceSettlementSupplierTotalList(page);
    }

    @ApiOperation(value = "通过开始时间和结束时间查询供应商的结算记录(供应商)")
    @PostMapping(value = "/queryFinaceSettlementHistoryByChoice")
    public ResultMessage<FinaceSettlementHistoryOperation> queryFinaceSettlementHistoryByChoice(@RequestBody @Valid PagePo<FinaceSettlementHistoryPo> page) {
        return finaceSettlementHistoryServiceImpl.queryFinaceSettlementHistoryByChoice(page);
    }


    @ApiOperation(value = "供应商查询财务管理收入明细")
    @PostMapping(value = "/getOperationFinaceIncomeDetailList")
    public ResultMessage<List<FinaceSupplierIncomeDetailsVo>> getOperationFinaceIncomeDetailList(@RequestBody @Valid PagePo<FinaceSupplierIncomeDetailsPo> page) throws BusinessException {
        //获取账号信息
        UserInfo currentUser = LocalData.getCurrentUser();
        page.getFields().setSupplierId(currentUser.getTypeId());
        return finaceOperationServiceImpl.feginOperationFinaceIncomeDetailList(page);
    }

    @ApiOperation(value = "供应商查询收入明细，初始化订单状态列表信息")
    @GetMapping(value = "/initOrderStatusList")
    public ResultMessage<List<DictionaryOrderPo>> get() {
        return finaceOperationServiceImpl.queryOrderStatusList();
    }


}
